﻿/**
 * @file button_process.c
 * @brief this is a brief description
 * @details this is the detail description.
 * @author fulong 
 * @data 8/21/2014
 * @version 1.0
 * @par Copyright (c):
 * @par First build
 *     version: fulong 
 *     data: 8/21/2014
 */
#include "XT11033_button_process.h"

#include "../../../../app/menu/menu_process.h"
#include "../../../../app/menu/menu_common.h"
#include "string.h"
#include "../../../../hal/display.h"
#include "../../../../hal/e2prom.h"
#include "../../../../dev/uart.h"
#include "../../../../hal/action/action.h"
#include "../../../../hal/hal_key.h"

#ifdef MENU_ENABLE
#ifdef __XT11033__
#define SELECT_PROGRAM_PASSWD 506
#define CONFIG_PARAM_PASSWD 123
extern uint8 param[ PARAM_MAX ];
void enter_passwd_button(void) {
    change_menu(2);
}
void menu_passwd_button_up(void) {
    ctrllable_widget_var_up(get_ctrllable_widget_pointer(), 10);
}
void menu_passwd_button_select(void) {
    uint8 ctrllable_num;
    ctrllable_num = get_left_ctrllable_widget();
    if (ctrllable_num != GET_CTRLLABLE_WRONG) {
        clr_ctrllable_widget_flash(get_ctrllable_widget_pointer());
        set_ctrllable_widget_pointer(ctrllable_num);
        set_ctrllable_widget_flash(get_ctrllable_widget_pointer());
    }
}
void menu_passwd_button_sure(void) {
    uint16 passwd;
    passwd = get_ctrllable_widget_var_value(7) * 100 + get_ctrllable_widget_var_value(8) * 10 + get_ctrllable_widget_var_value(9);
    set_ctrllable_widget_var_value(7, 0);
    set_ctrllable_widget_var_value(8, 0);
    set_ctrllable_widget_var_value(9, 0);
    if (passwd == SELECT_PROGRAM_PASSWD) {
        change_menu(5);
    } else if (passwd == CONFIG_PARAM_PASSWD) {
        change_menu(3);
    }
}
void menu_enter_setting_button_sure(void) {
    uint16 save;
    uint16 parm_num;
    parm_num = get_ctrllable_widget_var_value(14) * 10 + get_ctrllable_widget_var_value(15);
    save = read_action_param(parm_num);
    change_menu(4);
    set_ctrllable_widget_var_value(19, (save / 100) % 10);
    set_ctrllable_widget_var_value(20, (save / 10) % 10);
    set_ctrllable_widget_var_value(21, save % 10);
}
void menu_setting_button_sure(void) {
    uint16 save;
    uint8 parm_num;
    save = get_ctrllable_widget_var_value(19) * 100 + get_ctrllable_widget_var_value(20) * 10 + get_ctrllable_widget_var_value(21);
    change_menu(3);
    parm_num = get_ctrllable_widget_var_value(14) * 10 + get_ctrllable_widget_var_value(15);
    set_param(parm_num, save);
}
void menu_program_sel_button_sure(void) {
    uint16 save;
    //保存选择段
    //等待重启
    save = get_ctrllable_widget_var_value(26) * 10 + get_ctrllable_widget_var_value(27);
    set_param(101, save);
    while (1);
}
#endif
#endif
